package chalmers.game.subterranean.model.player;

import chalmers.game.subterranean.model.inventory.Inventory;
import chalmers.game.subterranean.model.items.IEquippableItem;
import chalmers.game.subterranean.model.items.Ladder;
import chalmers.game.subterranean.model.items.Pickaxe;
import chalmers.game.subterranean.model.items.TeleportItem;
import chalmers.game.subterranean.model.items.Torch;
import chalmers.game.subterranean.model.physics.MovableBody;
import chalmers.game.subterranean.model.world.IWorld;
import chalmers.game.subterranean.util.Direction;
import chalmers.game.subterranean.util.Position;
import chalmers.game.subterranean.util.options.PlayerValues;

/**
 * Silly skeleton factory for player.
 * 
 * @author Alex Evert
 */
public class PlayerFactory {

  private Pickaxe pickAxe;

  public static IPlayer createPlayer(IWorld world) {
    // Create objects
    StateGround groundState = new StateGround();
    StateAir airState = new StateAir();
    StateWall wallState = new StateWall();
    StateLadder ladderState = new StateLadder();
    MovableBody body = new MovableBody();
    body.setWorld(world);
    PlayerContext player = new PlayerContext();
    // Set player start inventory items. // TODO remove some items later, when shop is done.
    IEquippableItem pickAxe = new Pickaxe(world);
    IEquippableItem ladder = new Ladder(world);
    IEquippableItem teleport = new TeleportItem(world);
    player.setEquippedItem(pickAxe);
    player.setWorld(world);
    Inventory inventory = new Inventory();
    inventory.addItem(pickAxe);
    inventory.addItem(ladder);
    inventory.addItem(teleport);
    Torch torch = new Torch(PlayerValues.TORCH_DEFAULT_BURNTIME);
    player.setTorch(torch);
    // TODO : Let the world give the player a start pos.
    Position startPosition = PlayerValues.PLAYER_START_POSITION;
    // Couple objects.
    airState.setPlayer(player);
    wallState.setPlayer(player);
    groundState.setPlayer(player);
    ladderState.setPlayer(player);
    player.setBody(body);
    player.setCurrentState(airState);
    player.setAirState(airState);
    player.setGroundState(groundState);
    player.setLadderState(ladderState);
    player.setWallState(wallState);
    player.setInventory(inventory);
    // Set initial values for the player.
    body.setPosition(startPosition);
    player.setLookDirection(Direction.EAST);
    // Return the player
    return player;
  }
}
